﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacadeSingTowerMall;

namespace WebFormSingTowerMall.HallBooking
{
    public partial class SpecifyHall : HallBookingBaseController
    {
        AvailableEventHallFacade favailhalls = new AvailableEventHallFacade();
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            currentPage = "SpecifyHall.aspx";

            Calendar1.Visible = false;
            Calendar2.Visible = false;    
        }

        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            if (EventHallGrid.SelectedRow == null)
            {
                string script = "alert('Please select Hall for Event Booking');";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

            } else {
                bookingDetails.hallId = Convert.ToInt32(EventHallGrid.SelectedRow.Cells[1].Text);
                bookingDetails.hallName = EventHallGrid.SelectedRow.Cells[2].Text;

                bookingDetails.pricePerDay = Convert.ToDecimal(EventHallGrid.SelectedRow.Cells[5].Text);
                NextPage();
                //System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert("Hello this is an Alert")</SCRIPT>");
                //System.Web.HttpContext.Current.Response.Write("Hello this is an Alert");
            }

            
        }

        protected void EventHallGrid_Row(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void Search_btn_Click(object sender, EventArgs e)
        {
            string datesValidationString = null;
            DateTime startDate;
            DateTime endDate;
            try {
                 startDate = Convert.ToDateTime(bkStDtTimetxtbx.Text);
                 endDate = Convert.ToDateTime(bkEndDtTimetxtbx.Text);
            } catch {
                datesValidationString = "Check if Event Start date or End date is empty ";
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", datesValidationString, true);
                return;
            }

            datesValidationString = bookingFacade.fValidate(startDate, endDate);

            if (datesValidationString != "Success")
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", datesValidationString, true);
            } else {
                EventHallGrid.DataSource = favailhalls.getAvailableEventHalls(bkStDtTimetxtbx.Text, bkEndDtTimetxtbx.Text);
                //EventHallGrid.DataSource = favailhalls.getAvailableEventHalls();
                EventHallGrid.DataBind();
            }

        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            Calendar1.Visible = false;
            bkStDtTimetxtbx.Text = Calendar1.SelectedDate.ToShortDateString() + " " + Calendar1.SelectedDate.ToShortTimeString();
            bookingDetails.eventStartDate = Convert.ToDateTime(bkStDtTimetxtbx.Text);
            
        }

        protected void Calendar2_SelectionChanged(object sender, EventArgs e)
        {
            Calendar2.Visible = false;
            bkEndDtTimetxtbx.Text = Calendar2.SelectedDate.ToShortDateString() + " " + Calendar2.SelectedDate.ToShortTimeString();
            bookingDetails.eventEndDate = Convert.ToDateTime(bkEndDtTimetxtbx.Text);
        }

        protected void startCalender_Click(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;
        }

        protected void endCalender_Click(object sender, ImageClickEventArgs e)
        {
            Calendar2.Visible = true;
        }

        protected void EventHallGrid_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}